package com.hl.sfzy.controller;

import com.hl.sfzy.entity.LogonUser;
import com.hl.sfzy.service.RegisterUserService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: sfzy
 * @description: 孙源源-用户注册
 * @author: Syy
 * @create: 2024-09-07 15:24
 **/
@RestController
@RequestMapping("/user")
public class RegisterUserController {
    @Autowired
    private RegisterUserService registerUserService;

    //注册接口1
    @PostMapping("/register")
    public R register(LogonUser logonUser) {
        return R.success(registerUserService.register(logonUser));
    }

    //判断手机号是否已注册接口
    @GetMapping("/select")
    public R select(String phone) {
        int i = registerUserService.selectByPhone(phone);
        if (i == 1) {
            return R.success(i);//可以注册
        } else {
            return R.failure(i);//不可注册
        }
    }

    //注册接口2
    @PostMapping("/register2")
    public R register2(String phone, String username, String password) {
        System.out.println(phone);
        System.out.println(username);
        System.out.println(password);
        int i = registerUserService.register2(phone, username, password);
        if (i == 1) {
            return R.success(i);
        } else return R.failure(i);
    }

    //判断用户名是否已注册接口
    @GetMapping("/select2")
    public R select2(String username) {
        int i = registerUserService.selectByUsername(username);
        if (i == 1) {
            return R.success(i);//可以注册
        } else {
            return R.failure(i);//不可注册
        }
    }
}
